package utilities.utilities_components;
import org.zkoss.zul.Auxhead;
import org.zkoss.zul.Auxheader;
import org.zkoss.zul.Column;
import org.zkoss.zul.Columns;
import org.zkoss.zul.Doublebox;
import org.zkoss.zul.Grid;
import org.zkoss.zul.Intbox;
import org.zkoss.zul.Label;
import org.zkoss.zul.Row;
import org.zkoss.zul.Rows;
import org.zkoss.zul.Window;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import utilities.Updatable;

public class GridBox extends Window implements Updatable{
	private Grid grid;
	private Auxhead head;
	private Auxheader aux;
	private Columns cols;
	private Column col;
	private Rows rows;
	private Row row;
	
	private Label label;
	private Intbox intbox;
	private Doublebox doubleBox;
	
	private String[] columns;
	private int colNum;
	
	public GridBox( String[] columns ){
		super();
		
		colNum = columns.length;
		
		this.columns = columns;
		
		createGridCap();
		createGridBody();
		
		this.appendChild( grid );
	}
	
	@Override
	public void setDisable(boolean disabled) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void update( List data ){
		
	}
	
	private void createGridCap(){
		/*  Create grid  */
		grid = new Grid();
		
		/*  Create auxiliary head  */
		head = new Auxhead();
		grid.appendChild( head );
		
		/*  Create auxiliary head  */
		aux = new Auxheader();
		aux.setAlign( "center" );
		aux.setColspan( 2 * columns.length );
		
		head.appendChild( aux );
		
		/*  Create columns  */
		cols = new Columns();
		grid.appendChild( cols );
		
		for( int count = 0; count < 2 * columns.length; count++ ){
			col = new Column();
			col.setAlign( "center" );
			col.setLabel( columns[ count % columns.length ] );
			cols.appendChild( col );
		}
	}
	
	private void createGridBody(){
		rows = new Rows();
		
		for( int line = 0; line < 16; line++ ){
			row = new Row();
			rows.appendChild( row );
			
			label = new Label( "" + ( line + 1 ) );
			row.appendChild( label );
			
			intbox = new Intbox( 0 );
			row.appendChild( intbox );
			
			for( int count = 0; count < columns.length - 2; count++ ){
				doubleBox = new Doublebox( 0.00 );
				/*  Format goes here  */
				doubleBox.setFormat( "0.00" );
				row.appendChild( doubleBox );
			}
			
			label = new Label( "" + ( line + 17 ) );
			row.appendChild( label );
			
			intbox = new Intbox( 0 );
			row.appendChild( intbox );
			
			for( int count = 0; count < columns.length - 2; count++ ){
				doubleBox = new Doublebox( 0.00 );
				/*  Format goes here  */
				doubleBox.setFormat( "0.00" );
				row.appendChild( doubleBox );
			}
		}
		
		/*  Change last cell  */
		label.setValue( "合计" );
		
		grid.appendChild( rows );
	}
}
